﻿using Platformer_Example.Controller.Character.Attack;
using Platformer_Example.Controller.Character.Behavior;
using Platformer_Example.Controller.Data;
using Platformer_Example.Controller.Input;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Rendering;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Platformer_Example.Controller.Character.Player
{
    public partial class Player : BaseInputCharacter
    {
        private static int shaderId;

        private static readonly TE_Rectangle Collision =
            new TE_Rectangle(0, -0.05f, 0.85f, 1.3f, TE_Rectangle.Alignment.BottomMiddle).ToGridBound();

        private static readonly TE_Rectangle _collisionLadder =
            new TE_Rectangle(0, -0.25f, 0.05f, 1, TE_Rectangle.Alignment.BottomMiddle).ToGridBound();

        private static readonly TE_Rectangle _collisionWarp =
            new TE_Rectangle(0, 0, 0.125f, 0.125f, TE_Rectangle.Alignment.CenterMiddle).ToGridBound();

        private static readonly TE_Rectangle _collisionHit = new TE_Rectangle(0, 0, 1, 2, TE_Rectangle.Alignment.BottomMiddle).ToGridBound();

        private readonly string _shaderId;
        public Player(InputState inputState, Team team) : base(inputState, team)
        {
            ChangeBehavior(new BaseBehavior());

            shaderId++;
            _shaderId = "playerShader-" + shaderId;
            ShaderHandler.AddShader(_shaderId, null, "Content/Shaders/ColorSwap.frag");
            ShaderHandler.SetParameter(_shaderId, "sourceColor", new Color(255, 0, 255));
            ShaderHandler.SetParameter(_shaderId, "targetColor", Team.GetColor());
            ShaderHandler.SetParameter(_shaderId, "tol", 0);
        }

        public Map.Map Map
        {
            get { return Parent.Parent.Parent as Map.Map; }
        }

        public override void Draw()
        {
            ShaderHandler.SetParameter(_shaderId, "maskColor", Character.Color);
            ShaderHandler.SetShader(_shaderId);
            base.Draw();
            ShaderHandler.RemoveShader();
        }

        public override TE_Rectangle GetCollisionBox()
        {
            return Collision;
        }

        public override void Reflect()
        {
            throw new System.NotImplementedException();
        }

        public override bool IsAttackable()
        {
            #warning Change this! There MUST be invincibility frames
            return true;
        }

        public override bool IsDefending()
        {
            #warning Change this! The player MUST be able to defend
            return false;
        }

        public override bool IsReflecting()
        {
            #warning Change this! The player MUST be able to reflect stuff
            return false;
        }

        public override TE_Rectangle GetHitBoundingBox()
        {
            return _collisionHit;
        }
    }
}